using System;
using Framework.Library.Core.Utils.Miscellaneous;

namespace Framework.Library.Core.Utils.Web.UI.Controls
{
    public class DateValidator : BaseRegularExpressionValidator
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            ValidationExpression = ValidationUtils.DateRegex;
        }

        protected override bool EvaluateIsValid()
        {
            bool isValid = base.EvaluateIsValid();

            if (!isValid)
            {
                return isValid;
            }
            else
            {
                // double check by parsing input in .NET
                string input = GetControlValidationValue(ControlToValidate);

                DateTime result;
                return DateTime.TryParse(input, out result);
            }
        }
    }
}